package com.example.book.controller;

import com.example.book.model.UserInfo;
import com.example.book.service.UserService;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/User")
@RestController
public class UserController {
    @Autowired
    UserService userService;
@RequestMapping("/login")
    public  String login(String username, String password, HttpSession session){
    UserInfo userInfo=userService.login(username,password);
    if(!StringUtils.hasLength(userInfo.getUserName())||!StringUtils.hasLength(userInfo.getPassword())){
        return "用户名或密码为空";
    }
    if("admin".equals(userInfo.getUserName())||"admin".equals(userInfo.getPassword())){
        return "用户名或密码错误";
    }
    session.setAttribute("username",username);
    return "";
}

}
